﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ColumnController : MonoBehaviour {

	GameObject[] cols;
	int curCol = 0;
	public GameObject colPrefab;
	public int colMax = 5;
	Vector2 originalPos = new Vector2(-10, -20); // position cannot be seen by player

	public float spawnRate = 3f;
	public float yMin = -1f;
	public float yMax = 3.5f;
	public float xPos = 10f;
	float timeSinceLastSpawned; // last generate time

	// Use this for initialization
	void Start () {
		cols = new GameObject[colMax];
		for (int i = 0; i < colMax; i++) {
			cols [i] = Instantiate (colPrefab, originalPos, Quaternion.identity);
	}
	}
	
	// Update is called once per frame
	void Update () {
		timeSinceLastSpawned += Time.deltaTime;
		if (!GameMode.instance.gameOver && timeSinceLastSpawned >= spawnRate) {
			timeSinceLastSpawned = 0f;
			float yPos = Random.Range (yMin, yMax);
			cols [curCol].transform.position = new Vector2 (xPos, yPos);
			curCol++;
			if (curCol >= colMax) {
				curCol = 0;
			}
		}
	}
}
